import { createRouter, createWebHistory } from 'vue-router';
import HomeView from '../views/HomeView.vue';

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta: {
      title: '首页',
    },
  },
  // 这里可以添加更多路由
  // {
  //   path: '/your-route',
  //   name: 'yourRoute',
  //   component: YourComponent,
  //   meta: {
  //     title: '页面标题',
  //   },
  // },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = `${to.meta.title} - 应用`;
  } else {
    document.title = '应用';
  }
  next();
});

export default router;